package hot;

public class ersanba {
//    https://leetcode.cn/problems/product-of-array-except-self/submissions/679943365/?envType=study-plan-v2&envId=top-100-liked

    class Solution {
        public int[] productExceptSelf(int[] nums) {
            int n=nums.length;
            int[] leftnum=new int[n];
            int[] rightnum=new int[n];
            int[] res=new int[n];
            leftnum[0]=1;
            rightnum[n-1]=1;
            for(int i=1;i<n;i++){
                leftnum[i]=leftnum[i-1]*nums[i-1];
            }
            for(int i=n-2;i>=0;i--){
                rightnum[i]=rightnum[i+1]*nums[i+1];
            }
            for(int i=0;i<n;i++){
                res[i]=leftnum[i]*rightnum[i];
            }
            return res;

        }
    }
}
